package main

import (
	"bufio"
	"fmt"
	"io"
	"math/rand"
	"net/http"
	"os"
	"path"
	"time"

	"github.com/Mrs4s/go-cqhttp/lib/qq"
)

func random(min, max int64) int64 {
	rand.Seed(time.Now().Unix())
	return rand.Int63n(max-min) + min
}

func main() {

	// s := random(-50, 50)
	flag, coins := qq.Five(2, 1)
	// s := cache.GetRedis().SetSign(115)
	// s := model.GetUserCoinsByUserID(1112)
	fmt.Printf("f: %v , c:%v\n", flag, coins)

	//定义命令行参数方式1
	// RequestUrl("https://imgpc.iimzt.com/2020/09/14a01.jpg")
}

func RequestUrl(url string) {
	client := &http.Client{}
	req, err := http.NewRequest(http.MethodGet, url, nil)
	if err != nil {
		return
	}
	req.Header.Add("Referer", "https://www.mzitu.com/")
	resp, err := client.Do(req)
	if err != nil {
		return
	}
	defer resp.Body.Close()
	// Load the HTML document
	imgPath := fmt.Sprintf("%s%s/", "./public/", time.Now().Format("20060102"))
	err = os.Mkdir(imgPath, os.ModePerm)
	if err != nil {
		return
	}
	// 根据图片url获取其文件名
	name := fmt.Sprintf("%s%s", time.Now().Format("150405"), path.Base(url))

	reader := bufio.NewReaderSize(resp.Body, 0)
	file, err := os.Create(imgPath + name)
	if err != nil {
		return
	}
	defer file.Close()
	// 获得文件的writer对象
	writer := bufio.NewWriter(file)
	_, err = io.Copy(writer, reader)
	if err != nil {
		return
	}
	writer.Flush()
	return
}
